package com.ocl.www;

import com.ocl.www.config.DynamicDataSourceRegister;
//import com.ocl.www.utils.QiniuTest;
//import com.qiniu.api.auth.AuthException;
//import match.Matching;
//import org.apache.log4j.PropertyConfigurator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication
@EnableTransactionManagement
@EnableAutoConfiguration
@Import({DynamicDataSourceRegister.class}) // 注册动态多数据源
public class Application extends SpringBootServletInitializer {

//	protected static void main(String[] args) throws Exception {
//		SpringApplication.run(Application.class, args);
//		//启动后加载特征值库
//		Matching.loadFeatures();
//	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//文件最大
		factory.setMaxFileSize("10240KB"); //KB,MB
		/// 设置总上传数据总大小
		factory.setMaxRequestSize("102400KB");
		return factory.createMultipartConfig();
	}

	@Override
	public  WebApplicationContext run(SpringApplication sa) {
		super.run(sa);
		return null;

//    	Matching.test();
//		System.out.println("加载lib图库OS");
//		System.out.println(Runtime.getRuntime().maxMemory());
//		System.out.println("Runtime.totalMemory():"+Runtime.getRuntime().totalMemory());
//		try{
// 			  初始化log4j
//            String log4jPath = this.getClass().getClassLoader().getResource("").getPath()+"log4j.properties";
//            String respath = log4jPath.substring(1, log4jPath.length());
//            System.out.println( this.getClass().getClassLoader().getResource("").getPath());
//            System.out.println("初始化Log4j。。。。");
//            System.out.println("path is "+ respath);
//            PropertyConfigurator.configure(Application.class.getResourceAsStream("/log4j.properties"));
//        }catch (Exception e){e.printStackTrace();}
//        sa.addListeners(new MyApplicationStartedEventListener());
    }


}
